import {
  DIC
} from '@/const/dic'

export const option = {
  index: true,
  indexLabel: '序号',
  border: true,
  selection: true,
  menuBtn: true,
  addBtn: false,
  cellBtn: false,
  editBtn: false,
  delBtn: false,
  columnBtn: false,
  refreshBtn: false,
  searchBtn: false,
  size: 'mini',
  dicData: DIC,
  align: "center",
  menuWidth: 220,
  menuAlign: "center",
  column: [
   {
    label: "规范概要",
    prop: "speSum",
    width: "90",
    slot: true
  },{
    label: "协议特征",
    prop: "protCha",
    width: "100",
  },{
    label: "接入建议",
    prop: "acSug",
      width: "140",
  },{
    label: "阅读说明",
    prop: "readIns",
      width: "140",
  },{
    label: "创建时间",
    prop: "createTime",
      width: "140",
  }
 ]
};



// 设备输入规则
export const sbRules = {
  /* string */
  speSum: [{
      required: true,
      message: '此项不能为空',
      trigger: 'blur'
    }
  ],
  protCha: [{
    required: true,
    message: '此项不能为空',
    trigger: 'blur'
  }
],
acSug: [{
  required: true,
  message: '此项不能为空',
  trigger: 'blur'
}
],
readIns: [{
  required: true,
  message: '此项不能为空',
  trigger: 'blur'
}
],
}
export function jsonToArray(nodes) {
  var r=[];
  if (Array.isArray(nodes)) {
    for (var i=0, l=nodes.length; i<l; i++) {
      r.push(nodes[i]); // 取每项数据放入一个新数组
      if (Array.isArray(nodes[i]["children"])&&nodes[i]["children"].length>0)
       // 若存在children则递归调用，把数据拼接到新数组中，并且删除该children
        r = r.concat(jsonToArray(nodes[i]["children"]));
          delete nodes[i]["children"]
    }
  } 
  return r;
}
export const serverArr = (data, value) => {
  let retrunData = []
  for (let i = 0; i < data.length; i++)
    data.forEach(item => {
      if (item.value == value) {
        retrunData = [item.value];
      } else {
        if (item.children) {
          let msg = serverArr (item.children, value)
          if (msg && msg.length != 0) {
            msg.unshift(item.value)
            retrunData = msg;
          }
        }
      }
    })
  return retrunData;
}